import { useVbenForm } from '#/adapter/form';
// 如果是目录是没有组件路径和权限标识的
// 只有菜单是有组件路径和权限标识的
export function menuForm(handleSubmit: any) {
  return useVbenForm({
    // 所有表单项共用，可单独在表单内覆盖
    commonConfig: {
      // 所有表单项
      componentProps: {
        class: 'w-full',
      },
    },
    // 提交函数
    handleSubmit,
    layout: 'horizontal',
    schema: [
      {
        fieldName: 'menuId',
        component: 'Input',
        label: 'ID',
        dependencies: {
          show: false,
          triggerFields: ['menuId'],
        },
      },
      {
        fieldName: 'parentId',
        component: 'Input',
        label: '上级ID',
        defaultValue: 0,
        dependencies: {
          show: false,
          triggerFields: ['menuId'],
        },
        componentProps: {
          disabled: true,
          placeholder: '请填写上级ID',
        },
        rules: 'required',
      },
      {
        fieldName: 'menuType',
        component: 'RadioGroup',
        label: '分类',
        componentProps: {
          options: [
            { label: '目录', value: 'M' },
            { label: '菜单', value: 'C' },
          ],
        },
        rules: 'required',
      },
      {
        fieldName: 'menuName',
        component: 'Input',
        label: '菜单标题',
        componentProps: {
          placeholder: '请输入路由标题',
        },
        rules: 'required',
      },
      {
        fieldName: 'path',
        component: 'Input',
        label: '路径',
        componentProps: {
          placeholder: '请填写路径',
          extra: '路径内容填写 http 地址则为外链网页',
        },
        rules: 'required',
      },
      {
        fieldName: 'component',
        component: 'Input',
        label: '组件路径',
        help: '分类为 [菜单] 则为页面路由地址 ,  [内嵌/外链] 则打开网页',
        componentProps: {
          placeholder: '请填写组件',
        },
        dependencies: {
          if(values) {
            return values.menuType === 'C';
          },
          // 只有指定的字段改变时，才会触发
          triggerFields: ['menuType'],
        },
      },

      {
        fieldName: 'permission',
        component: 'Input',
        label: '权限标识',
        componentProps: {
          placeholder: '请输入路由权限码',
        },
        dependencies: {
          if(values) {
            return values.menuType === 'C';
          },
          // 只有指定的字段改变时，才会触发
          triggerFields: ['menuType'],
        },
      },
      {
        fieldName: 'icon',
        component: 'IconPicker',
        label: '图标',
        rules: 'required',
      },
      {
        fieldName: 'status',
        component: 'RadioGroup',
        label: '菜单状态',
        defaultValue: true,
        componentProps() {
          return {
            options: [
              { label: '正常', value: '0' },
              { label: '停用', value: '1' },
            ],
          };
        },
      },
      {
        label: '显示状态',
        fieldName: 'visible',
        component: 'RadioGroup',
        help: '菜单是否可见,隐藏的话则可以正常路由跳转,但是菜单栏不会显示',
        defaultValue: true,
        componentProps: {
          options: [
            { label: '显示', value: '0' },
            { label: '隐藏', value: '1' },
          ],
        },
      },
      {
        fieldName: 'isCache',
        component: 'RadioGroup',
        label: '是否缓存',
        help: '开启后页面会缓存，不会重新加载，仅在标签页启用时有效',
        defaultValue: 0,
        componentProps: {
          options: [
            { label: '是', value: '0' },
            { label: '否', value: '1' },
          ],
        },
      },
      {
        fieldName: 'isFrame',
        component: 'RadioGroup',
        label: '是否外链',
        defaultValue: 1,
        componentProps: {
          options: [
            { label: '否', value: '1' },
            { label: '是', value: '0' },
          ],
        },
      },
      {
        fieldName: 'orderNum',
        component: 'InputNumber',
        label: '排序',
        defaultValue: 0,
        componentProps: {
          placeholder: '请填写排序',
          help: '数值越小优先级越高',
          min: 0,
          max: 100,
        },
      },
      {
        fieldName: 'remark',
        component: 'Textarea',
        label: '描述',
        componentProps: {
          placeholder: '请填写描述信息',
          rows: 4,
        },
      },
    ],
  });
}
